package com.lan.java8;

import com.alibaba.fastjson.JSON;
import com.lan.java8.antlr.Java8Lexer;
import com.lan.java8.antlr.Java8Parser;
import com.lan.java8.model.info.PackageRoot;
import org.antlr.v4.runtime.*;

import java.io.IOException;
import java.io.InputStream;
import java.lang.System;

class Test {


    public static void main(String[] args) throws IOException {
//        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("helloworld.java");
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("base/User.java");
//        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("IUserService.java");

//        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("UserService.java");
//        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("UserDao.java");
        CharStream cs = CharStreams.fromStream(is);
        Java8Lexer lexer = new Java8Lexer(cs);

        CommonTokenStream tokens = new CommonTokenStream(lexer);
        Java8Parser parser = new Java8Parser(tokens);

//        Java8Parser.CompilationUnitContext context = parser.compilationUnit();
//        System.out.println(context.toStringTree());


//        parser.addErrorListener(new DiagnosticErrorListener());
//        parser.setErrorHandler(new BailErrorStrategy());
//        parser.getInterpreter().setPredictionMode(PredictionMode.SLL);


//        Java8Parser.PackageNameContext context = parser.packageName();
//        System.out.println(context.toStringTree());


//        Java8Parser.TypeImportOnDemandDeclarationContext context = parser.typeImportOnDemandDeclaration();

//        Java8Parser.PackageDeclarationContext context = parser.packageDeclaration();
//        System.out.println(context.toStringTree());

        Java8Parser.CompilationUnitContext context = parser.compilationUnit();
        PackageRoot root = new PackageRoot();
        root.start(context);
        System.out.println(JSON.toJSONString(root));
    }


}
